home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kcrash.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-19  |  4.1 KB  |  128 lines

  1. /*
  2.  * This file is part of the KDE Libraries
  3.  * Copyright (C) 2000 Timo Hummel <timo.hummel@sap.com>
  4.  *                    Tom Braun <braunt@fh-konstanz.de>
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public License
  16.  * along with this library; see the file COPYING.LIB.  If not, write to
  17.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19.  *
  20.  */
  21.  
  22. #ifndef __KCRASH_H
  23. #define __KCRASH_H
  24.  
  25. #include <qstring.h>
  26. #include "kdelibs_export.h"
  27.  
  28. /**
  29.  * This class handles segmentation-faults.
  30.  * By default it displays a  message-box saying the application crashed.
  31.  * This default can be overridden by setting a custom crash handler with
  32.  * setCrashHandler().
  33.  * If a function is specified with setEmergencySaveFunction() it will
  34.  * be called by the default crash handler, giving the application a chance
  35.  * to save its data.
  36.  */
  37. class KDECORE_EXPORT KCrash
  38. {
  39.  private: // ;o)
  40.   static const char *appName;
  41.   static const char *appPath;
  42.   static bool safer;
  43.  
  44.  public:
  45.   /**
  46.    * The default crash handler.
  47.    * @param signal the signal number
  48.    */
  49.   static void defaultCrashHandler (int signal);
  50.  
  51.   /**
  52.    * This function type is a pointer to a crash handler function.
  53.    * The function's argument is the number of the signal.
  54.    */
  55.   typedef void (*HandlerType)(int);
  56.  
  57.   /**
  58.    * Install a function to be called in case a SIGSEGV is caught.
  59.    * @param handler HandlerType handler can be one of
  60.    * @li null in which case signal-catching is disabled
  61.    *  (by calling signal(SIGSEGV, SIG_DFL))
  62.    * @li if handler is omitted the default crash handler is installed.
  63.    * @li an user defined function in the form:
  64.    * static (if in a class) void myCrashHandler(int);
  65.    * @param handler the crash handler
  66.    */
  67.  
  68.   static void setCrashHandler (HandlerType handler = defaultCrashHandler);
  69.  
  70.   /**
  71.    * Returns the installed crash handler.
  72.    * @return the crash handler
  73.    */
  74.   static HandlerType crashHandler() { return _crashHandler; }
  75.  
  76.   /**
  77.    * Installs a function which should try to save the applications data.
  78.    * It is the crash handler┤s responsibility to call this function.
  79.    * Therefore, if no crash handler is set, the default crash handler
  80.    * is installed to ensure the save function is called.
  81.    * @param saveFunction the handler to install
  82.    */
  83.   static void setEmergencySaveFunction (HandlerType saveFunction = (HandlerType)0);
  84.   /**
  85.    * Return the currently set emergency save function.
  86.    * @return the emergency save function
  87.    */
  88.   static HandlerType emergencySaveFunction() { return _emergencySaveFunction; }
  89.  
  90.   /**
  91.    * Set whether to start drkonqi without arbitrary disk access
  92.    */
  93.   static void setSafer( bool on ) { safer = on; }
  94.  
  95.   /**
  96.    * Sets the application @p path which should be passed to
  97.    * Dr. Konqi, our nice crash display application.
  98.    * @param path the application path.
  99.    */
  100.   static void setApplicationPath (QString path) { appPath = qstrdup(path.local8Bit().data()); }
  101.   /* KDE 4: Make it const QString & */
  102.  
  103.   /**
  104.    * Sets the application name @p name which should be passed to
  105.    * Dr. Konqi, our nice crash display application.
  106.    * @param name the name of the application, as shown in Dr. Konqi
  107.    */
  108.   static void setApplicationName (QString name) { appName = qstrdup(name.local8Bit().data()); }
  109.   /* KDE 4: Make it const QString & */
  110.  
  111.  protected:
  112.   /**
  113.    * Pointer to the crash handler.
  114.    */
  115.   static HandlerType _crashHandler;
  116.   /**
  117.    * Pointer to the emergency save function.
  118.    */
  119.   static HandlerType _emergencySaveFunction;
  120.   
  121.  private:
  122.    static void startDrKonqi( const char* argv[], int argc );
  123.    static void startDirectly( const char* argv[], int argc );
  124. };
  125.  
  126. #endif
  127.  
  128.